########################################
# Handlers for restarting services
#

- name: reload systemd
  command: systemctl daemon-reload

- name: restart apache
  command: /usr/local/bin/conditional-restart.sh httpd httpd

- name: reload apache
  action: service name=httpd state=reloaded

- name: restart collectd
  action: service name=collectd state=restarted

- name: restart crond
  action: service name=crond state=restarted

- name: restart fedmsg-gateway
  command: /usr/local/bin/conditional-restart.sh fedmsg-gateway

- name: restart fedmsg-hub
  command: /usr/local/bin/conditional-restart.sh {{ item }}
  with_items:
  - fedmsg-hub
  - fedmsg-hub-3

- name: restart fedmsg-hub-3
  command: /usr/local/bin/conditional-restart.sh {{ item }}
  with_items:
  - fedmsg-hub
  - fedmsg-hub-3

- name: restart fedmsg-irc
  command: /usr/local/bin/conditional-restart.sh fedmsg-irc

- name: restart fedmsg-relay
  command: /usr/local/bin/conditional-restart.sh fedmsg-relay

- name: restart fm-consumer@koji_sync_listener
  action: service name=fm-consumer@koji_sync_listener state=restarted enabled=yes

- name: reload httpd
  command: /usr/local/bin/conditional-reload.sh httpd httpd

- name: restart iptables
  action: service name=iptables state=restarted

- name: restart ip6tables
  action: service name=ip6tables state=restarted

- name: restart libvirtd
  action: service name=libvirtd state=restarted

- name: restart libvirtd.socket
  action: service name=libvirtd.socket state=stopped
  notify: restart libvirtd

- name: restart mailman
  action: service name=mailman state=restarted

- name: restart named
  action: service name=named state=restarted

- name: restart ntpd
  action: service name=ntpd state=restarted

- name: restart sshd
  action: service name=sshd state=restarted

- name: restart openvpn (Fedora)
  when: ansible_distribution == "Fedora"
  action: service name=openvpn-client@openvpn state=restarted
  #notify:
  #- fix openvpn routing

- name: restart openvpn (RHEL7+)
  when: ansible_distribution == "RedHat" and ansible_distribution_major_version|int >= 7
  action: service name=openvpn-client@openvpn state=restarted
  #notify:
  #- fix openvpn routing

- name: fix openvpn routing
  action: shell /etc/openvpn/fix-routes.sh

- name: restart xinetd
  action: service name=xinetd state=restarted
  when: not inventory_hostname.startswith('proxy')

- name: restart netapproute
  action: command /etc/sysconfig/network-scripts/ifup-routes eth1

- name: restart network
  action: service name=network state=restarted

- name: rebuild postfix transport
  command: /usr/sbin/postmap /etc/postfix/transport

- name: rebuild postfix bysender
  command: /usr/sbin/postmap /etc/postfix/bysender

- name: rebuild postfix tls_policy
  command: /usr/sbin/postmap /etc/postfix/tls_policy

- name: restart postfix
  service: name=postfix state=restarted

- name: reload proxyhttpd
  command: /usr/local/bin/proxy-conditional-reload.sh httpd httpd

- name: restart glusterd
  service: name=glusterd state=restarted

- name: run rkhunter
  command: rkhunter --propupd

- name: restart moksha-hub
  service: name=moksha-hub state=restarted

- name: restart dhcpd
  service: name=dhcpd state=restarted

- name: restart memcached
  service: name=memcached state=restarted

- name: restart nagios
  shell: nagios -v /etc/nagios/nagios.cfg && systemctl restart nagios

- name: restart bridge
  shell: /usr/lib/systemd/systemd-sysctl --prefix=/proc/sys/net/bridge

- name: reload libvirtd
  service: name=libvirtd state=reloaded
  ignore_errors: true
  when: ansible_virtualization_role == 'host'

- name: restart pagure_ev
  service: name=pagure_ev state=restarted

- name: "update ca-trust"
  command: /usr/bin/update-ca-trust

- name: restart stunnel
  service: name=stunnel state=restarted

- name: restart mirrorlist-server
  service: name=mirrorlist-server state=restarted

- name: restart NetworkManager
  service: name=NetworkManager state=restarted

- name: reload NetworkManager-connections
  command: nmcli c reload

- name: restart basset-worker
  service: name=basset-worker state=restarted

- name: apply interface-changes
  command: nmcli con up {{ item.split()[1] }}
  async: 1
  poll: 0
  loop: "{{ if_uuid.stdout_lines|flatten(levels=1) }}"
  when: item.split()[1] not in ansible_ifcfg_disabled

- name: flush journald tmpfiles to persistent store
  command: pkill -f -USR1 systemd-journald

- name: restart idmapd
  service: name=nfs-idmapd state=restarted

- name: restart buildmaster
  service: name=buildmaster state=restarted

- name: restart rabbitmq
  systemd:
    name: rabbitmq-server
    state: restarted
    daemon_reload: yes

- name: restart chronyd
  service: name=chronyd state=restarted

- name: restart mbs poller
  systemd:
    name: mbs-poller
    state: restarted
  when: not mbs_frontend

- name: restart mbs workers
  systemd:
    name: "mbs-worker@{{ item }}"
    state: restarted
  with_sequence: start=0 end={{ mbs_num_workers - 1 }}
  when: not mbs_frontend

- name: restart kojira
  systemd:
    name: kojira
    state: restarted

- name: restart haveged
  service: name=haveged state=restarted

- name: restart obs-signd
  service: name=signd state=restarted

- name: restart swap.swap
  service: name="swap.swap" state=restarted

- name: restart varnish
  service: name=varnish state=restarted

- name: reload varnish
  service: name=varnish state=reload
